library(rvest)
library(writexl)
library(readxl)
library(dplyr)
library(lubridate)
library(haven)
library(effsize)

surveys <- read_xlsx("newsurveys.xlsx")
surveys <- filter(surveys, sample %in% c("national adult","national adult with oversample"))
surveys$year <- year(surveys$enddate)
temp <- filter(surveys, method == "phone" & !is.na(`response rate`))

unique(x$sample)
mysurveys <- read_xlsx("newsurveys.xlsx")
mysurveys <- filter(mysurveys, sample %in% c("national adult","national adult with oversample") &
                      method == "phone" & !is.na(`response rate`))
for(i in 1:nrow(mysurveys)){
  rm(x)
  try(load(paste0("roper_data/",mysurveys$survey[i],"/",mysurveys$survey[i],".RData")))
  try(write_dta(x,paste0("roper_data/",mysurveys$survey[i],"/",mysurveys$survey[i],".dta"), version = 13))
  print(i)
}
